/**
 * udes.ds.rmi
 * BasicEquation.java
 * 3 sept. 08
 */
package ift605.tp3.utils.equations;

import java.math.BigDecimal;

/**
 * Stores an equation of the type kx^n
 * 
 * @author Luc Bergevin
 * @version 1.0
 * @see
 */
public class PowEq extends AbstractEq implements ISimpleEquation, IBinaireEquation
{
    
    private static final long serialVersionUID = 1L;
    private final double _coefficient;
    private final double _exponent;
    
    public PowEq(double coefficient, double exponent)
    {
        super();
        _coefficient = coefficient;
        _exponent = exponent;
    }
    
    public double getCoefficient()
    {
        return _coefficient;
    }
    
    public double getExponent()
    {
        return _exponent < 0 ? 0 : _exponent;
    }
    
    /**
     * @see udes.ds.IEquation.hw.Equation#getFunctionValue(double)
     */
    public double getFunctionValue(double x)
    {
        return ((Math.pow(x, _exponent)) * _coefficient);
    }
    
    /**
     * @see udes.ds.rmi.hw.AbstractEq#getUserReadableString()
     */
    @Override
    public String getUserReadableString()
    {
        return new String(Double.toString(_coefficient) + "x^" + Double.toString(_exponent));
    }
    
    @Override
    public double getX()
    {
        return getCoefficient();
    }
    
    @Override
    public double getY()
    {
        return getExponent();
    }
    
    @Override
    public BigDecimal eval(BigDecimal x)
    {
        return x.pow((int) getExponent()).multiply(BigDecimal.valueOf(_coefficient));
    }
    
}
